﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Assist;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;

namespace HYFloorPipeModule
{
	public partial class DefineFloorPipeForm : System.Windows.Forms.Form
	{
		public double PipeDN { get; set; }

		public string PipeMaterial { get; set; }

		public double Radius { get; set; }

		public DefineFloorPipeForm()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			this.Text = "盘管参数设置";
			this.InitForm();
		}

		private void InitForm()
		{
			string[] array = new string[]
			{
				"PPR",
				"PE-X",
				"PB",
				"PE-RT"
			};
			this.cmbPipeMaterial.DataSource = array;
			string text = this.userSetting.ReadValue("DefineFloorPipe", "PipeMaterial");
			string text2 = this.userSetting.ReadValue("DefineFloorPipe", "PipeDN");
			string text3 = this.userSetting.ReadValue("DefineFloorPipe", "Radius");
			if (array.Contains(text))
			{
				this.cmbPipeMaterial.SelectedItem = text;
			}
			else
			{
				this.cmbPipeMaterial.SelectedIndex = 0;
			}
			this.hytbPipeDN.Text = ((text2 == "") ? "20" : text2);
			this.hytbRadius.Text = ((text3 == "") ? "160" : text3);
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			this.SaveData();
			base.DialogResult = DialogResult.OK;
			base.Close();
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void SaveData()
		{
			this.PipeDN = double.Parse(this.hytbPipeDN.Text.Trim());
			this.Radius = double.Parse(this.hytbRadius.Text.Trim());
			this.PipeMaterial = this.cmbPipeMaterial.Text;
			this.userSetting.WriteValue("DefineFloorPipe", "PipeMaterial", this.PipeMaterial);
			this.userSetting.WriteValue("DefineFloorPipe", "PipeDN", this.PipeDN.ToString());
			this.userSetting.WriteValue("DefineFloorPipe", "Radius", this.Radius.ToString());
		}

		private void hyTextBox1_Validating(object sender, CancelEventArgs e)
		{
			double num = double.Parse(this.hytbPipeDN.Text);
			double num2 = double.Parse(this.hytbRadius.Text);
			if ((num2 < 8.0 * num || num2 > 11.0 * num) && DialogResult.No == YJKMessageBox.Show("根据《辐射供暖供冷技术规程》JGJ 142-2012中5.4.3的规定，塑\n料管弯曲半径不应小于管道外径的8倍，最大弯曲半径不得大于\n管道外径的11倍。是否使用当前转角半径数值？", MessageBoxButtons.YesNo))
			{
				this.hytbRadius.Undo();
				this.hytbRadius.Focus();
			}
		}

		private HVACUserSetting userSetting = new HVACUserSetting();
	}
}
